package com.ycy.dubbo.controller;

import com.ycy.dubbo.entity.YcyResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 消费端 使用 Ribbon 和 RestTemplate 来调用服务提供者。
 */
@RestController
public class RestTemplateController {

  @Autowired
  private RestTemplate restTemplate;

  @GetMapping("/time")
  public YcyResponse getTime() {
    YcyResponse forObject = restTemplate.getForObject("http://ycy-provider:8880/time", YcyResponse.class);
    return forObject;
  }

}
